﻿using UnityEngine;
using System.Collections;

public class Card : MonoBehaviour {

	public bool inHand;
	public float height;
	public float width;
	public enum type {champion, item, summonerspell};
	public type myType;
	public bool menuOpen = false;
	public bool player1Card;
	public string cardName;
	public string cardDescription;

	public Texture cardSprite;
	[HideInInspector]public bool viewMenuOpen;

	public int handPositon = 0;

	public float buttonWidth;
	public float buttonHeight;

	public bool isInGraveyard;

	// Use this for initialization
	public void initializeStuff () {
		buttonWidth = GameController.gc.buttonSize.x;
		buttonHeight = GameController.gc.buttonSize.y;
	}

	public void openMenu(){

	}

	public void play(){

	}

	public void view(){
		if(!GameController.gc.gameover)
			viewMenuOpen = true;
	}

	public void closeMenu(){
		menuOpen = false;
		GameController.gc.doingSomethingElse = false;
	}

	void OnMouseDown(){
		if(!GameController.gc.doingSomethingElse && !isInGraveyard && !GameController.gc.gameover){
			menuOpen = true;
			GameController.gc.doingSomethingElse = true;
		}
	}

	public void removeBackground(){
		int numChildren = transform.childCount;
		for(int i = 0; i < numChildren; i++){
			Transform childTransform = transform.GetChild(i);
			if(childTransform.CompareTag("cardbackground"))
			   Destroy(childTransform.gameObject);
		}
	}

	public IEnumerator putUnderChampion(Champion champion){
		yield return new WaitForSeconds(GameController.gc.animationTime);
		transform.position = new Vector3(transform.position.x, transform.position.y, champion.transform.position.z+1);
	}

	public IEnumerator waitToPutInGraveyard(){
		yield return new WaitForSeconds(GameController.gc.animationTime);
		sendToGraveyard();
	}

	public void sendToGraveyard(){
		Vector3 graveYardPosition = new Vector3(0,0,0);
		if(player1Card){
			graveYardPosition = GameController.gc.playerOneGraveyard.transform.position;
		}
		else
			graveYardPosition = GameController.gc.playerTwoGraveyard.transform.position;
		transform.position = graveYardPosition;
		isInGraveyard = true;
	}
}
